<?php
/*
Plugin Name: Emailserving plug-in
Plugin URI: http://www.emailserving.com/
Description: Emailserving Subscriber List plugin allows you to generate an email list to use for your Emailserving campaigns from your WordPress Blog subscribers in just seconds.  This plugin makes it easy for you to collect new email subscribers or sales leads for your email marketing campaigns.  
Author: Yesup Inc.
Version: 1.0
Author URI: http://www.yesup.com/
*/

include_once('functions.php');

/*
 * Version check
*/
global $wp_version;

if( !version_compare($wp_version,'3.0', '>=')){
	die("You need at least version 3.0 of Wordpress to use the copyright plugin.");
}

/*
 * Initalize Plugin
 * 		1. Plugin Activation code
 *		2. Plugin Deactivation code 
*/



function es_activate(){
	$post_id = wp_insert_post(array("post_title" => "es-sync-page", "post_content" => "","post_type" => "page", 'post_status' => 'publish', 'post_author' => 1));
	if(!empty($post_id)){
		update_option('es_sync_post_id', $post_id);		
	}
}

function es_deactivate(){
	$post_id = get_option('es_sync_post_id');
	if(!empty($post_id)){
		wp_delete_post( $post_id, true ); // wp_delete_post( $post_id, $force_delete );
	}
	delete_option('es_api_url');
	delete_option('es_api_key');
	delete_option('es_sync_post_id');
	delete_option('es_user_name');
	delete_option('es_list_id');
	delete_option('es_list_name');
	delete_option('es_list_size');
	delete_option('es_list_active');
	delete_option('es_list_inactive');
	delete_option('es_list_optout');
}


register_activation_hook(__FILE__,'es_activate');
register_deactivation_hook(__FILE__,'es_deactivate');


/*
 * CSS file include
*/
function es_admin_css_all_page() {
	//Register the style handle
    wp_register_style($handle = 'es-admin-css-all', $src = plugins_url('css/admin-all.css', __FILE__), $deps = array(), $ver = '1.0.0', $media = 'all');
 
	//Now enqueue it
    wp_enqueue_style('es-admin-css-all');
}
add_action('admin_print_styles', 'es_admin_css_all_page');


/*
 * Template Filter (assign template file es-sync-template.php to newly created page)
 * 		1. Check es-sync-template
*/

function es_page_template( $page_template )
{
    if ( is_page( 'es-sync-page' ) ) {
        $page_template = dirname( __FILE__ ) . '/es-sync-template.php';
    }
    return $page_template;
	
}

add_filter( 'page_template', 'es_page_template' );

/*
 * Admin Control
 * 		1. Output User Interface
 *		2. Display Config Datas
 *		3. Update Config Datas
*/
include('es_admin.php');







